package cn.jhc.teachingquality.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by luyanfei on 16-4-20.
 */
public class CountLessonsUtils {
    private static final Pattern PERIOD_PATTERN = Pattern.compile("\\[(\\d+)-(\\d+)节\\]");

    public static int countLessonsFromString(String periodDescription){
        Matcher matcher = PERIOD_PATTERN.matcher(periodDescription);
        int count = 0;
        if(matcher.find()){
            try {
                Integer begin = Integer.valueOf(matcher.group(1));
                Integer end = Integer.valueOf(matcher.group(2));
                count = end - begin + 1;
            } catch (NumberFormatException e) {
                e.printStackTrace();
                count = 0;
            }
        }
        return count;
    }
}
